<template>
  <div class="app-container">
    <el-tabs type="border-card" v-model="modeType">
      <el-tab-pane label="师徒佣金" name="apprentice">
        师傅介绍徒弟超过
        <span
          ><el-input-number
            :controls="false"
            style="width: 100px"
            v-model="setting.apprenticeNum"
            disabled
          ></el-input-number
        ></span>
        人，获得徒弟"已完成"订单金额
        <span
          ><el-input-number
            :controls="false"
            style="width: 100px"
            v-model="setting.commissionRatio"
            disabled
          ></el-input-number
        ></span>
        %作为奖励佣金。
      </el-tab-pane>
      <el-tab-pane label="好评订单" name="commission">
        好评订单获得
        <span
          ><el-input-number
            :controls="false"
            style="width: 100px"
            v-model="setting.amount"
            disabled
          ></el-input-number
        ></span>
        元奖励佣金。
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import { apiSystemConfigList, apiSystemConfig } from "@/api/bail.js";
export default {
  components: {},
  data() {
    return {
      modeType: "apprentice",
      setting: {
        apprenticeNum: "0", //学徒数量，
        commissionRatio: "0", //佣金比例
        amount: "0", //好评奖励
      },
    };
  },
  mounted() {
    this.getData();
  },
  methods: {
    getData() {
      apiSystemConfigList().then((res) => {
        res.data.forEach((item) => {
          if (item.configKey == "worker.commission.apprentice.num") {
            this.setting.apprenticeNum = item.configValue;
            this.setting.apprentice_configId = item.configId;
          } else if (
            item.configKey == "worker.commission.apprentice.commissionRatio"
          ) {
            this.setting.commissionRatio = item.configValue;
            this.setting.commissionRatio_configId = item.configId;
          } else if (item.configKey === "worker.security.commission.amount") {
            this.setting.amount = item.configValue;
            this.setting.amount_configId = item.configId;
          }
        });
      });
    },
    handleSubmit(values) {
      if (this.modeType == "apprentice") {
        const params = {
          configKey: "worker.commission.apprentice.num",
          configId: this.setting.apprentice_configId,
          configName: "师徒佣金配置-邀请几个徒弟",
          configValue: values.apprenticeNum,
        };
        const req1 = apiSystemConfig(params);
        const params2 = {
          configId: values.commissionRatio_configId,
          configKey: "worker.commission.apprentice.commissionRatio",
          configName: "师徒佣金配置-得到的佣金比例",
          configValue: values.commissionRatio,
        };
        const req2 = apiSystemConfig(params2);
        Promise.all([req1, req2]).then((res) => {
          this.$message({ type: "success", message: "修改成功" });
        });
      } else {
        const params3 = {
          configId: values.amount_configId,
          configKey: "worker.security.commission.amount",
          configName: "好评订单配置-好评订单给师傅的佣金",
          configValue: values.amount,
        };
        const req3 = apiSystemConfig(params3);
        Promise.all([req3]).then((res) => {
          this.$message({ type: "success", message: "修改成功" });
        });
      }
    },
  },
};
</script>
<style scoped lang="scss">
span {
  color: orangered;
}
::v-deep .el-tabs__content {
  height: calc(100vh - 170px);
  overflow: auto;
}
::v-deep .el-input {
  width: 100px;
  display: inline-block;
}
</style>
